package acm.pta5;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main
{

    static class edge implements Comparable<edge>
    {
        String name;
        int zan, zong;

        public edge(String name, int zan, int zong)
        {
            this.name = name;
            this.zan = zan;
            this.zong = zong;
        }

        @Override
        public int compareTo(edge other)
        {
            if (other.zan != this.zan)
                return other.zan - this.zan;
            return this.zong - other.zong;
        }
    }

    public static void main(String[] args) throws IOException
    {
        int n = sc.nextInt();
        ArrayList<edge> ar = new ArrayList<edge>();
        for (int i = 1; i <= n; i++)
        {
            String name = sc.next();
            int k = sc.nextInt();

            TreeSet<Integer> tr = new TreeSet<Integer>();
            for (int j = 1; j <= k; j++)
            {
                int f = sc.nextInt();
                tr.add(f);
            }
            ar.add(new edge(name, tr.size(), k));
        }
        Collections.sort(ar);
        for (int i = 0; i < Math.min(n, 3); i++)
        {
            if (i != 0)
                out.print(" ");
            out.print(ar.get(i).name);
        }
        for (int i = n; i < 3; i++)
            out.print(" -");

        out.flush();
        out.close();
    }

    static InputReader sc = new InputReader();
    static PrintWriter out = new PrintWriter(System.out);

    static class InputReader
    {
        private InputStream inputStream = System.in;
        private byte[] buf = new byte[100000];
        private int curChar;
        private int numChars;

        public int getchar()
        {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars)
            {
                curChar = 0;
                try
                {
                    numChars = inputStream.read(buf);
                } catch (IOException e)
                {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt()
        {
            int a = 0, b = 1;
            int c = getchar();
            while (c < '0' || c > '9')
            {
                if (c == '-')
                {
                    b = -1;
                }
                c = getchar();
            }
            while (c >= '0' && c <= '9')
            {
                a = (a << 1) + (a << 3) + (c ^ 48);
                c = getchar();
            }
            return a * b;
        }

        public String next()
        {
            int c = getchar();
            while (c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1)
            {
                c = getchar();
            }
            StringBuilder res = new StringBuilder();
            do
            {
                if (Character.isValidCodePoint(c))
                    res.appendCodePoint(c);
                c = getchar();
            } while (!(c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1));
            return res.toString();
        }
    }

}
